<?
	require_once $PathToRoot . 'connect.php';
	require_once $PathToRoot . 'util.php';

	function DoLogMessage ($LogMessage)
	{	global $SecurityEngaged, $hostname, $username, $password, $dbase, $LogTable;

		if (!$LogMessage || !strlen ($LogMessage))
			return;
		$connect = @mysql_connect ($hostname, $username, $password);
		if (!$connect) {
			return;
		}
		mysql_select_db ($dbase, $connect);
		mysql_query ('SET CHARACTER SET cp1251', $connect);
		$sql = "INSERT INTO " . $LogTable . " VALUES (" .
			"'" . date ("Y-m-d G:i:s") . "'" .
			",'" . to_db($LogMessage) . "'" .
			")";
		$result = @mysql_query ($sql, $connect);
		mysql_close ($connect);
	}

	function LogScriptAccess ($Success, $Reason)
	{	global $hostname, $username, $password;

		$LogMessage = 	$_SERVER ["SCRIPT_NAME"] . ': ' . $_COOKIE['Name'] .
				", IP address: " . $_SERVER ["REMOTE_ADDR"] . ", " .
				"Session = " . $_COOKIE ["admin_session_code"] . ". ";
		if ($Success) {
			$LogMessage .= "Access granted.";
		}
		else {
			$LogMessage .= "Access denied. " . $Reason;
		}
		DoLogMessage ($LogMessage);
	}
?>